{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "741678c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tuple, tuple, tuple, int, tuple)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 1,2,3,4,5,6,7\n",
    "b = (1, 2, 3, 4, 5, 6, 7)\n",
    "c = (42,)\n",
    "d = (42)\n",
    "f = ()\n",
    "type(a),type(b),type(c),type(d),type(f)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb113fcd",
   "metadata": {},
   "source": [
    "tuple()生成元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "935cdc6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('a', 's', 'd', 'a', 's', 'd')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = tuple(\"asdasd\")\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9f0f526d",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = tuple(range(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c48283dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d953d6c",
   "metadata": {},
   "source": [
    "元组元素不能修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "17e8ee7c",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_2320/2572514506.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"3\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "a[2]=\"3\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "42b873e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('a', 's', 'd', 'a', 's', 'd')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b347f737",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'a', 'd', 'd', 's', 's']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23e56c6d",
   "metadata": {},
   "source": [
    "zip()操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "411197f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((10, 20), (20, 39), (30, 24))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [10 ,20 ,30]\n",
    "b = [20 , 39, 24]\n",
    "c = zip(a,b)\n",
    "tuple(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "364646ee",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_test",
   "language": "python",
   "name": "my_test"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
